<?php

include_once('admin.php');

/**
 * This class provides dynamic data (autocomplete, etc) for the staff pages.
 * @package staff
 */
class jquery extends admin
{
	/**
	 * Returns a json encoded list of variables from specified table and field based on input from $_POST('term')
	 * @param $table_name Name of table
	 * @param $field_name Name of field 
	 * @return string
	 */
	function autocomplete( $table_name, $field_name )
	{
		// Search term from jQuery
		$term = $this->input->post('term');
			
		$this->load->model('jquery_model');			
		$rows = $this->jquery_model->getAutocomplete($table_name, $field_name, $term);
			
		$keywords = array();
		foreach ($rows as $row)
			array_push($keywords, $row->$field_name);

		echo json_encode($keywords);		
	}
}

?>